package com.yfp.goods.controller;

import cn.hutool.core.bean.BeanUtil;
import com.yfp.common.core.domain.R;
import com.yfp.common.core.utils.poi.ExcelUtil;
import com.yfp.common.core.web.controller.BaseController;
import com.yfp.common.core.web.page.TableDataInfo;
import com.yfp.goods.domain.TagCombo;
import com.yfp.goods.domain.vo.TagComboExportVO;
import com.yfp.goods.service.TagComboService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 套餐标签(TagCombo)表控制层
 *
 *
 * @since 2023-12-27 14:20:28
 */
@RestController
@RequestMapping("tagCombo")
@Tag(name = "套餐标签管理")
public class TagComboController extends BaseController {
    /**
     * 服务对象
     */
    @Resource
    private TagComboService tagComboService;

    /**
     * 分页查询
     *
     * @param tagCombo 筛选条件
     * @return 查询结果
     */
    @GetMapping
    @Operation(summary = "分页查询")
    public TableDataInfo queryByPage(TagCombo tagCombo) {
        startPage();
        return getDataTable(this.tagComboService.queryAll(tagCombo));
    }

    @PostMapping("/export")
    @Operation(summary = "套餐标签导出")
    public void export(HttpServletResponse response, TagCombo tagCombo){
        List<TagCombo> tagCombos = tagComboService.queryAll(tagCombo);
        List<TagComboExportVO> tagComboExportVOS = BeanUtil.copyToList(tagCombos, TagComboExportVO.class);

        ExcelUtil<TagComboExportVO> util = new ExcelUtil<>(TagComboExportVO.class);
        util.exportExcel(response, tagComboExportVOS, "套餐标签");
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    @Operation(summary = "通过主键查询单条数据")
    public R<TagCombo> queryById(@PathVariable("id") String id) {
        return R.ok(this.tagComboService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param tagCombo
     * @return 新增结果
     */
    @PostMapping
    @Operation(summary = "新增套餐标签")
    public R<TagCombo> add(@RequestBody TagCombo tagCombo) {
        return R.ok(this.tagComboService.addComboTag(tagCombo));
    }

    /**
     * 编辑数据
     *
     * @param tagId tagName
     * @return 编辑结果
     */
    @PutMapping
    @Operation(summary = "修改套餐标签")
    public R<TagCombo> edit(@RequestParam String tagId, @RequestParam String tagName, @RequestParam String color, @RequestParam String cityName) {
        return R.ok(this.tagComboService.updateComboTag(tagId,tagName,color,cityName));
    }

    @PutMapping("dis")
    @Operation(summary = "禁用/启用标签")
    public R disableTag(@RequestParam String tagId) {
        return this.tagComboService.disableTag(tagId) ? R.ok() : R.fail();
    }

}

